<?php

include_once 'db.php';

class User extends Db {

    public $table_name = "user";

    public function __construct() {
        parent::__construct();
    }

    public function select($email) {
        /**
         * TODO: Write your code here
         */
        $query = 'SELECT * FROM '.$this->table_name.' WHERE email = "'.$email.'"';//SQL query
        $data = parent::select($query);
        return $data;
    }
    public function selectAll($params) {
        /**
         * TODO: Write your code here
         */
        $query = 'SELECT * FROM '.$this->table_name.'';//SQL query
        if (!empty($params['offset'])) {
            $offset = ($params['offset'] - 1) * PER_PAGE;
            $query .= ' LIMIT ' . $offset . ', ' . PER_PAGE;
        }
        $data = parent::select($query);
        return $data;
    }
    public function count()
    {
        $query = "SELECT COUNT(*) AS COUNT FROM {$this->table_name}";
        $data = parent::select($query);
        if(!empty($data[0]['COUNT']))
            return (int)$data[0]['COUNT'];
        return 0;
    }
    public function insert($name,$email,$pass) {
        /**
         * TODO: Write your code here
         */
        $query = 'INSERT INTO '.$this->table_name.' (id,name,email,pass,per) VALUES ("","'.$name.'","'.$email.'","'.$pass.'","3")';//SQL query
        var_dump($query);
        $data = parent::insert($query);
        return $data;
    }
    public function update($id,$per) {
        /**
         * TODO: Write your code here
         */
        $query = 'UPDATE '.$this->table_name.' SET per = '.$per.' WHERE id = '.$id;//SQL query
        $data = parent::update($query);
        return $data;
    }
    public function updatepass($email,$pass) {
        /**
         * TODO: Write your code here
         */
        $query = 'UPDATE '.$this->table_name.' SET pass = '.$pass.' WHERE email = "'.$email.'"';//SQL query
        $data = parent::update($query);
        return $data;
    }
    public function block($id,$block) {
        /**
         * TODO: Write your code here
         */
        $query = 'UPDATE '.$this->table_name.' SET block = '.$block.' WHERE id = '.$id;//SQL query
        $data = parent::update($query);
        return $data;
    }
    public function delete($id) {
        /**
         * TODO: Write your code here
         */
        $query = 'DELETE FROM '.$this->table_name.' WHERE id = '.$id;//SQL query
        $data = parent::delete($query);
        return $data;
    }

}
